<#compress>

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,  user-scalable=0;" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style"  />
    <meta content="telephone=no" name="format-detection" />
    <link rel="stylesheet" href="${ctx}/static/mobileweb/1/css/common.css?_=${.now?string('yyyy-MM-dd')}">
    <title>中南币兑换</title>
</head>
<body>
<ul class="topboxshow">
    <li class="coins">
        <span class="stitle">中南币</span><span class="num" id="curcurrency">${member.currency!}</span>
    </li>
    <li class="integral">
        <span class="stitle">积分</span><span class="num" id="curintegral">${member.add_integral_value!}</span>
    </li>
    <br class="cb"/>
</ul>

<div class="commonbox">
    <ul class="exchange">
        <li>
            <span class="stitle">中南币</span>
            <br/>
            <input type="text" id="currency" class="textInp" value="0"/>
        </li>
        <li class="equal">=</li>
        <li>
            <span class="stitle">积分</span>
            <br/>
            <input type="text" id="integral" readonly class="textInp" value="0"/>
        </li>
        <br class="cb"/>
    </ul>
    <p class="lackbalance" id="tip" style="display: none"></p>
    <p class="exchangebtns center">
        <a href="javascript:void(0);" class="mr20" id="exchange">兑换</a>
        <a href="javascript:void(0);" id="reset">重置</a>
    </p>
</div>

<p class="exchangtitle">规则</p>
<ul class="commonbox rulesList">
    <li>${cti.currency!}中南币=${cti.integral!}积分</li>
    <li>积分和中南币可以相互转换</li>
</ul>
</body>
<script type="text/javascript" src="${ctx}/static/mobileweb/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideToolbar');
    });
    $(function() {
        var re = /^-?\d+\.?\d{0,1}$/;
        var scale = ${cti.integral!}/${cti.currency!};
        var curcurrency = ${member.currency!};
        var curintegral = ${member.add_integral_value!};
        var phone = '${member.phone!}';

        $("#currency").focus(function() {
            $("#tip").hide();
        });

        $("#currency").keyup(function() {
            var currency = $(this).val().trim();
            if (currency) {
                if (re.test(currency)) {
                    $("#integral").val(currency * scale);
                }
            }
        });

        $("#exchange").click(function() {

            if (!phone) {
                $("#tip").html("请先绑定会员").show();
                return;
            }

            var currency = $("#currency").val().trim();
            if (!re.test(currency)) {
                $("#tip").html("请输入合法数值").show();
                return;
            }
            if (currency > curcurrency) {
                $("#tip").html("中南币余额不足").show();
                return;
            }
            var integral = $("#integral").val().trim();
            if (integral == 0 || currency == 0) {
                $("#tip").html("请输入兑换值").show();
                return;
            }
            $.post("${ctx}/mobileweb/currency/exchangeSave", {mid : "${mid}", currency : currency, integral: integral}, function(data) {
                if (data.status == 'OK') {
                    curcurrency = curcurrency - parseFloat(currency);
                    curintegral = curintegral + parseFloat(integral);
                    $("#curcurrency").html(curcurrency);
                    $("#curintegral").html(curintegral);
                    $("#tip").html(data.message).show();
                } else {
                    $("#tip").html(data.message).show();
                }
            });
        });

        $("#reset").click(function() {
            $("#currency").val(0);
            $("#integral").val(0);
        });


    });
</script>
</html>
</#compress>
